﻿using System;
using System.IO;

namespace MyLib.IO {
	/// <summary>
	/// 
	/// </summary>
	[Serializable]
	public sealed class FileObject {
		/// <summary>
		/// 
		/// </summary>
		public string Id { get; private set; }

		/// <summary>
		/// 
		/// </summary>
		public int FileType { get; private set; }

		/// <summary>
		/// 
		/// </summary>
		public string ObjectId { get; private set; }

		/// <summary>
		/// 
		/// </summary>
		public long Size { get; private set; }

		/// <summary>
		/// 
		/// </summary>
		public string Name { get; private set; }

		/// <summary>
		/// 
		/// </summary>
		public string Description { get; private set; }

		/// <summary>
		/// 
		/// </summary>
		public string Summary { get; private set; }

		/// <summary>
		/// 
		/// </summary>
		public DateTime LastWriteTime { get; private set; }

		/// <summary>
		/// 
		/// </summary>
		public FileObjectAttr Attr { get; private set; }

		/// <summary>
		/// 
		/// </summary>
		/// <param name="id"></param>
		/// <param name="name"></param>
		/// <param name="fileType"></param>
		/// <param name="objectId"></param>
		/// <param name="size"></param>
		/// <param name="lastWriteTime"></param>
		/// <param name="description"></param>
		/// <param name="summary"></param>
		/// <param name="attr"></param>
		public FileObject(string id, string name, int fileType, string objectId, long size, DateTime lastWriteTime, string description = "", string summary = "", FileObjectAttr attr = FileObjectAttr.None) {
			Id = id;
			Name = name;
			FileType = fileType;
			ObjectId = objectId;
			Size = size;
			Description = description;
			Summary = summary;
			LastWriteTime = lastWriteTime;
			Attr = attr;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="obj"></param>
		/// <returns></returns>
		public override bool Equals(object obj) {
			FileObject anfo = obj as FileObject;

			if (anfo == null)
				return false;

			return anfo.Id == this.Id;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public override int GetHashCode() {
			if (this.Id == null)
				return 0;
			else
				return this.Id.GetHashCode();
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public override string ToString() {
			return string.Format("{0}@{1}", Name, Id);
		}
	} // end of FileObject.

	/// <summary>
	/// 
	/// </summary>
	[Flags]
	public enum FileObjectAttr {
		/// <summary>
		/// 
		/// </summary>
		None = 0x0,

		/// <summary>
		/// 
		/// </summary>
		SubDirectory = 0x10,

		/// <summary>
		/// 
		/// </summary>
		ReadOnly = 0x01,

		/// <summary>
		/// 
		/// </summary>
		Hidden = 0x02
	} // end of FileObjectAttr.
}
